﻿using EFEntity;
using ISerives;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;


namespace HR.Controllers
{
    public class DenLuController : Controller
    {
        private readonly IUsersSerives ius;

        public DenLuController(IUsersSerives ius)
        {
            this.ius = ius;
        }
        [HttpGet]
        public IActionResult Login()
        {
            return View();
        }
        [HttpPost]
        public async Task<IActionResult> Login(users u)
        {
            //1。通过输入的用户名和密码查询数据库是否有此用户
            if (ModelState.IsValid)
            {
               if (await ius.Select(u.u_name,u.u_password) > 0)
                {
                   Eusers eu=await ius.Select_Show(u.u_name, u.u_password);
                    HttpContext.Session.SetString("user",eu.u_true_name);
                    return RedirectToAction("Index","YeMian");
                }
                else
                {
                    return RedirectToAction("Login");
                }

            }
            else
            {
                return View(u);
            }
        }
    }
}